package me.a04test;

import java.util.*;

public class Test4 {
    public static void main(String[] args) {
        //集合嵌套
        //一个省份有多个市
        HashMap<String, ArrayList<String>> hm = new HashMap<>();

        //创建单列集合存储市
        ArrayList<String> city1 = new ArrayList<>();
        Collections.addAll(city1, "南京", "苏州");

        ArrayList<String> city2 = new ArrayList<>();
        Collections.addAll(city2, "武汉", "宜昌");

        ArrayList<String> city3 = new ArrayList<>();
        Collections.addAll(city3, "保定", "邢台");

        hm.put("江苏省", city1);
        hm.put("湖北省", city2);
        hm.put("河北省", city3);

        //遍历
        Set<Map.Entry<String, ArrayList<String>>> entries = hm.entrySet();
        for (Map.Entry<String, ArrayList<String>> entry : entries) {
            //得到省和存储市的单列集合
            String key = entry.getKey();
            ArrayList<String> value = entry.getValue();
            //拼接字符串
            StringJoiner sj = new StringJoiner(", ", "", "");
            //遍历单列集合，拼接市
            for (String city : value) {
                sj.add(city);
            }
            System.out.println(key + " = " + sj);

        }
    }
}
